<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // typeof 可以正确识别：Undefined、Boolean、Number、String、Symbol、Function 等类型的数据
        // 但是对于其他的都会认为是 object，比如 null、Date 等
        console.log(typeof 1) // number
        console.log(typeof '1') // string
        console.log(typeof true) // boolean
        console.log(typeof undefined) // undefined
        console.log(typeof null) // object
        console.log(typeof {}) // object
        console.log(typeof []) // object
        console.log(typeof function(){}) // function
        console.log(typeof Symbol()) // symbol
        console.log(typeof BigInt(1)) // bigint
        console.log('.............................')
        // instanceof 可以正确的判断对象的类型，其内部运行机制是判断在其原型链中能否找到该类型的原型
        console.log(1 instanceof Number) // false
        console.log('1' instanceof String) // false
        console.log(true instanceof Boolean) // false
        // console.log(undefined instanceof Undefined) // false
        // console.log(null instanceof Null) // false
        console.log({} instanceof Object) // true
        console.log([] instanceof Array) // true
        console.log(function(){} instanceof Function) // true
        console.log(Symbol() instanceof Symbol) // false
        console.log(BigInt(1) instanceof BigInt) // false
        console.log('.............................')
        // Object.prototype.toString.call() 可以正确的判断类型，优先使用
        function getType(obj){
            return Object.prototype.toString.call(obj).slice(8,-1)
        }
        console.log(getType(1)) // Number
        console.log(getType('1')) // String
        console.log(getType(true)) // Boolean
        console.log(getType(undefined)) // Undefined
        console.log(getType(null)) // Null
        console.log(getType({})) // Object
        console.log(getType([])) // Array
        console.log(getType(function(){})) // Function
        console.log(getType(Symbol())) // Symbol
        console.log(getType(BigInt(1))) // BigInt
    </script>
</body>
</html>